import pandas as pd
from openpyxl import load_workbook
import flet as fl
def split_sheet():
    df=pd.read_csv('d:/NSK_TE.csv',encoding = 'utf-8')
    df.to_excel('d:/NSK_TE.xlsx',index=False)
    wb=load_workbook('d:/NSK_TE.xlsx')
    ws=wb.active
    #准备title
    title=['日期','时间','客户','模号','料号','送测人','投测类型','备注信息']
    fai_sheet=wb.create_sheet("FAI_CPK_GRR")
    fai_sheet.append(title)
    conf_sheet=wb.create_sheet("尺寸确认")
    conf_sheet.append(title)
    max_row=ws.max_row+1
    for i in range(2,max_row):
        if ws.cell(i,7).value=='尺寸确认':
            DATA=[]
            for j in range(1,9):
                DATA.append(ws.cell(i,j).value)
            conf_sheet.append(DATA)
        else:
            DATA=[]
            for j in range(1,9):
                DATA.append(ws.cell(i,j).value)
            fai_sheet.append(DATA)
    wb.save('d:/NSK_TE.xlsx')
def main(page:fl.Page):
    page.title="转换拆分EXCEL"
    page.window.width=180
    page.window.height=260
    label=fl.Text(value="将文件放置D盘\n命名为：NSK_TE.csv")
    def sp(e):
        split_sheet()
        btn.text="拆分完成"
        page.update()
    btn=fl.ElevatedButton(text="拆分",on_click=sp,width=200,height=150,style=fl.ButtonStyle(shape=fl.RoundedRectangleBorder(radius=4)),bgcolor="#3f51b5",color="white")
    page.add(label,btn)
fl.app(target=main)












'''










'''
